import { baseApiUrl, path } from "../../utils/config";
import { courseClassInfo, courseClassBuy } from '../../utils/api';
import paymentRequest from '../../utils/api';
import Toast from '@vant/weapp/toast/toast';
const app = getApp();
Page({
  data: {
    baseImageUrl: baseApiUrl,
    id: null,
    is_buy: true,
    cover: "",
    name: "",
    price: "",
    content: ""
  },
  async onLoad(options) {
    let { id } = options;
    this.setData({ id });
    this.getDeta();
  },
  async getDeta() {
    let { id } = this.data;
    let { is_buy, info } = await courseClassInfo({ id });
    let { name, price, content, thumbnail } = info;
    content = content?.replace(/\<img/gi, '<img style="width:100%;height:auto"');
    this.setData({ is_buy, cover: thumbnail, name, price, content });
  },
  async submit() {
    let { id } = this.data;
    let { pay_data } = await courseClassBuy({ id });
    await paymentRequest(pay_data);
    Toast('操作成功');
    this.getDeta();
  },
  onShareAppMessage() {
    let poster = app.globalData.poster;
    return {
      path,
      imageUrl: poster
    }
  },
  onShareTimeline() { }
})